package com.meida.module.system.provider.listener;

import com.meida.common.utils.RedisUtils;
import com.meida.module.system.provider.service.BaseConfigService;
import com.meida.module.system.provider.service.SysAreaService;
import com.meida.module.system.provider.service.SysDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;

/**
 * @author: flyme
 * @date: 2019/2/12 16:24
 * @desc: 初始化系统配置
 */
@Slf4j
public class SystemInitListener implements ApplicationListener<ApplicationReadyEvent>, Ordered {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private SysDictService dictService;
    @Autowired
    private SysAreaService areaService;

    @Autowired
    private BaseConfigService baseConfigService;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {

        log.info("服务已启动,准备初始化配置###################");
        if (applicationReadyEvent.getApplicationContext().getDisplayName().indexOf("AnnotationConfigServletWebServerApplicationContext") > -1) {
            dictService.initDictRedis();
            areaService.initArea();
            baseConfigService.initBaseConfig();
        }

    }

    @Override
    public int getOrder() {
        return 1;
    }
}
